package com.zoe.onelink.mybatis.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Strings;
import com.zoe.onelink.mybatis.base.dao.IBaseDao;
import com.zoe.onelink.mybatis.base.service.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2021</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2021-07-15
 */
public class BaseServiceImpl<Dao extends IBaseDao<Entity>, Entity> extends ServiceImpl<Dao, Entity> implements IBaseService<Entity> {

    @Autowired
    protected Dao baseDao;


    @Override
    public List<Entity> searchList(String query, Wrapper<Entity> queryWrapper) {
        if (Strings.isNullOrEmpty(query)) {
            return list(queryWrapper);
        } else {
            return this.baseDao.searchList(query, queryWrapper);
        }
    }

    @Override
    public <E extends IPage<Entity>> E searchPage(String query, E page, Wrapper<Entity> queryWrapper) {
        if (Strings.isNullOrEmpty(query)) {
            return page(page, queryWrapper);
        } else {
            return this.baseDao.searchPage(query, page, queryWrapper);

        }
    }
}
